package com.wx.day03.Work.Config;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import javax.sql.DataSource;

@Configuration
@PropertySource("classpath:jdbc.properties")
@ComponentScan({"com.wx.day03.Work.Controller","com.wx.day03.Work.Service","com.wx.day03.Work.Dao"})
public class JavaConfig {
    @Bean
    public DataSource dataSource(@Value("com.mysql.cj.jdbc.Driver") String driver, @Value("jdbc:mysql://192.168.254.134:3306/studb") String url,
                                 @Value("root") String user, @Value("esz8311l") String password) throws Exception {
        DruidDataSource druidDataSource = new DruidDataSource();
        druidDataSource.setDriverClassName(driver);
        druidDataSource.setUrl(url);
        druidDataSource.setUsername(user);
        druidDataSource.setPassword(password);
        return druidDataSource;
    }
}
